// 1.算法题：https://leetcode-cn.com/problems/lru-cache/
/**
 * @param {number} capacity
 */
 var LRUCache = function(capacity) {
    this.map = new Map();
    this.capacity = capacity;
};

/** 
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function(key) {
    if(this.map.has(key)){
        let value = this.map.get(key);
        this.map.delete(key);
        this.map.set(key, value);
        return value
    } else {
        return -1
    }
};

/** 
 * @param {number} key 
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function(key, value) {
    if(this.map.has(key)){
        this.map.delete(key);
    }
    this.map.set(key, value);
    if(this.map.size > this.capacity){
        this.map.delete(this.map.keys().next().value);
    }

};


// 2.手写题：https://bigfrontend.dev/problem/implement-Promise-race

/**
 * @param {Array<Promise>} promises
 * @return {Promise}
 */
 function race(promises) {
    // your code here
    return new Promise((resolove,reject)=>{
      promises.forEach(promise=>{
        promise.then(data=>resolove(data))
        .catch(err=>reject(err))
      })
    })
  }